package com.zr.controller.dispatch;

import com.github.pagehelper.PageInfo;
import com.zr.exception.BusinessException;
import com.zr.service.dispatch.DispatchTicketService;
import com.zr.utils.AjaxResult;
import com.zr.vo.car.CarInfo;
import com.zr.vo.dispatch.DispatchTicket;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.swing.plaf.PanelUI;
import java.util.List;

/**
 * @author 陈鹏
 */
@RestController
@RequestMapping("dispatch/ticket")
public class DispatchTicketController {
    @Resource
    private DispatchTicketService dispatchTicketService;

    /**
     * 条件查询调度单列表
     *
     * @param dispatchTicket
     * @return
     * @author 陈鹏
     */
    @RequestMapping("/list")
    public AjaxResult list(@RequestBody DispatchTicket dispatchTicket) {
        if (dispatchTicket.getCarInfo() == null) dispatchTicket.setCarInfo(new CarInfo());
        PageInfo<DispatchTicket> pageInfo = dispatchTicketService.list(dispatchTicket);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 新增调度单信息
     *
     * @param dispatchTicket
     * @return
     * @author 陈鹏
     */
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody DispatchTicket dispatchTicket) throws BusinessException {
        dispatchTicketService.add(dispatchTicket);
        return AjaxResult.success(200, "保存成功", null);
    }

    /**
     * 删除调度单信息
     *
     * @param dispatchTicket
     * @return
     * @author 陈鹏
     */
    @RequestMapping("/remove")
    public AjaxResult remove(@RequestBody DispatchTicket dispatchTicket) {
        dispatchTicketService.remove(dispatchTicket);
        return AjaxResult.success(200, "删除成功", null);
    }

    /**
     * 更新调度单信息
     *
     * @param dispatchTicket
     * @return
     * @throws BusinessException
     * @author 陈鹏
     */
    @RequestMapping("/update")
    public AjaxResult update(@RequestBody DispatchTicket dispatchTicket) throws BusinessException {
        dispatchTicketService.update(dispatchTicket);
        return AjaxResult.success(200, "修改成功", null);
    }

    /**
     * 查询所有调度单状态及其数量
     *
     * @return
     * @author 张荣颜
     */
    @RequestMapping("/statusList")
    public AjaxResult statusList() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.statusList());

    }

   

    /**查询当日新增调度单数量
     * @return
     * @author 张荣颜
     */
    @PostMapping("/getTodayAddQuantity")
    public int getTodayAddQuantity() {
        return dispatchTicketService.getTodayAddQuantity();
    }

    /** 查询最近6个月每个月的调度单数量
     * @return
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfDispatchQuantitySixMonths")
    public AjaxResult getChangeOfDispatchQuantitySixMonths() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getChangeOfDispatchQuantitySixMonths());
    }


    /** 查询最近一年每个月的调度单数量
     * @return
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfDispatchQuantityYear")
    public AjaxResult getChangeOfDispatchQuantityYear() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getChangeOfDispatchQuantityYear());
    }


    /** 查询最近30天每天的的调度单数量
     * @return
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfDispatchQuantityOneMonth")
    public AjaxResult getChangeOfDispatchQuantityOneMonth() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getChangeOfDispatchQuantityOneMonth());
    }

    /** 查询没有完成的调度单数量
     * @return
     * @author 张荣颜
     */
    @PostMapping("/getDispatchUnfinishedQuantity")
    public int getDispatchUnfinishedQuantity() {
        return dispatchTicketService.getDispatchUnfinishedQuantity();
    }

    /**
     * 查询所有运输中调度单信息列表
     *
     * @return PageInfo<DispatchTicket>
     * @author huangguilong
     */
    @RequestMapping("/listForTransportation")
    public AjaxResult listForTransportation(@RequestBody DispatchTicket dispatchTicket) {
        PageInfo<DispatchTicket> pageInfo = dispatchTicketService.listForTransportation(dispatchTicket);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 查询近7天运单数
     *
     * @return
     */
    @PostMapping("/getTicketDoneRecentWeek")
    public AjaxResult getTicketDoneRecentWeek() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getTicketDoneRecentWeek());
    }

    ;

    /**
     * 查询近30天运单数
     *
     * @return
     */
    @PostMapping("/getTicketDoneRecentMonth")
    public AjaxResult getTicketDoneRecentMonth() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getTicketDoneRecentMonth());
    }

    ;

    /**
     * 查询本年度运单数
     *
     * @return
     */
    @PostMapping("/getTicketDoneThisYear")
    public AjaxResult getTicketDoneThisYear() {
        return AjaxResult.success(200, "查询成功", dispatchTicketService.getTicketDoneThisYear());
    }

    ;
}



